<vi:ModuleViewBase x:Class="RapidDownloader.Modules.Views.DownloadQueueModule.DownloadQueueModule"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:vi="http://schemas.rhea.be/vidyano/2007/presentation"
             xmlns:shaders="clr-namespace:RapidDownloader.Modules.Views.Shaders"
             xmlns:markup="clr-namespace:RapidDownloader.Modules.Views.Markup"
             mc:Ignorable="d" d:DesignHeight="431" d:DesignWidth="725">

    <vi:ModuleViewBase.Resources>
        <markup:FormatSizeConverter x:Key="formatSize" />

        <Style TargetType="Button" x:Key="priorityButton">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border Cursor="Hand" Background="Transparent">
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Effect">
                                    <Setter.Value>
                                        <DropShadowEffect Opacity="0.5" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter Property="Effect">
                                    <Setter.Value>
                                        <DropShadowEffect Opacity="0.5" ShadowDepth="2" />
                                    </Setter.Value>
                                </Setter>
                                <Setter Property="RenderTransform">
                                    <Setter.Value>
                                        <TranslateTransform X="2" Y="2" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Opacity" Value="0.6" />
                                <Setter Property="Effect">
                                    <Setter.Value>
                                        <shaders:HueEffect Saturation="0" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </vi:ModuleViewBase.Resources>

    <DockPanel>
        <Border DockPanel.Dock="Top" Padding="5,8" Background="White">
            <StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
                <RadioButton IsChecked="{Binding AutoDownload, Mode=TwoWay}">
                    <RadioButton.Template>
                        <ControlTemplate TargetType="RadioButton">
                            <ToggleButton IsChecked="{Binding IsChecked, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
                                <ToggleButton.Content>
                                    <StackPanel Orientation="Horizontal" Margin="5, 0">
                                        <Image Source="Resources\Play.png" RenderOptions.BitmapScalingMode="HighQuality" Width="10" Margin="0, 0, 5, 0" x:Name="img">
                                            <Image.Effect>
                                                <shaders:HueEffect Hue="60" Saturation="2" />
                                            </Image.Effect>
                                        </Image>
                                        <TextBlock Text="Auto download ..." />
                                    </StackPanel>
                                </ToggleButton.Content>
                            </ToggleButton>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsChecked" Value="False">
                                    <Setter Property="Effect" TargetName="img">
                                        <Setter.Value>
                                            <shaders:HueEffect Saturation="0" />
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </RadioButton.Template>
                </RadioButton>

                <TextBlock Text="  |  " Foreground="LightGray" Margin="0, 5" />

                <TextBlock Text="Max downloads :  " FontWeight="Bold" VerticalAlignment="Center" />
                <ComboBox ItemsSource="{Binding MaxParallelDownloadChoices}" SelectedItem="{Binding MaxParallelDownloads}" VerticalAlignment="Center" />

                <TextBlock Text="  |  " Foreground="LightGray" Margin="0, 5" />

                <TextBlock Text="Average bandwidth :  " FontWeight="Bold" VerticalAlignment="Center" />
                <ComboBox ItemsSource="{Binding MaxBandwidthChoices}" SelectedItem="{Binding MaxBandwidth}" VerticalAlignment="Center">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Item1, Mode=OneTime}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>

                <TextBlock Text="  |  " Foreground="LightGray" Margin="0, 5" />

                <TextBlock Text="Max I/O buffer :  " FontWeight="Bold" VerticalAlignment="Center" />
                <ComboBox ItemsSource="{Binding MaxIOBufferChoices}" SelectedItem="{Binding MaxIOBuffer}" VerticalAlignment="Center">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Item1, Mode=OneTime}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
            </StackPanel>
        </Border>

        <Border DockPanel.Dock="Bottom">
            <Border Padding="3" BorderThickness="0, 1, 0, 0" BorderBrush="#FFAAAAAA">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Active downloads :  " FontWeight="Bold" VerticalAlignment="Center" />
                    <TextBlock Text="{Binding CurrentParallelDownloads}" VerticalAlignment="Center" />

                    <TextBlock Text="  |  " Foreground="LightGray" Margin="0, 5" VerticalAlignment="Center"/>

                    <TextBlock Text="Speed :  " FontWeight="Bold" VerticalAlignment="Center" />
                    <TextBlock Text="{Binding BandwidthUsage, Converter={StaticResource formatSize}, StringFormat='{}{0}/s'}" VerticalAlignment="Center" />

                    <TextBlock Text="  |  " Foreground="LightGray" Margin="0, 5" VerticalAlignment="Center"/>

                    <TextBlock Text="Time Remaining :  " FontWeight="Bold" VerticalAlignment="Center" />
                    <TextBlock Text="{Binding TimeRemaining}" VerticalAlignment="Center" />

                    <TextBlock Text="  |  " Foreground="LightGray" Margin="0, 5" VerticalAlignment="Center"/>

                    <TextBlock Text="IO buffer usage :  " FontWeight="Bold" VerticalAlignment="Center" />
                    <ProgressBar Minimum="0" Maximum="{Binding UsedIOBufferMax}" Width="200" Height="20" Value="{Binding UsedIOBuffer, Mode=OneWay}" />
                </StackPanel>
            </Border>
        </Border>

        <Grid Background="White">
            <ListView ItemsSource="{vi:ViewModelBinding QueuedDownloads}">
                <ListView.View>
                    <GridView>
                        <GridView.Columns>
                            <GridViewColumn Width="60">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Grid HorizontalAlignment="Center">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*" />
                                                <ColumnDefinition Width="*" />
                                            </Grid.ColumnDefinitions>

                                            <Button Grid.Column="0" Margin="0,0,4,0" Style="{StaticResource priorityButton}" vi:ViewModel.Scope="MoveUpInQueue">
                                                <Button.Content>
                                                    <Image Source="Resources\Up.ico" Width="18" RenderOptions.BitmapScalingMode="HighQuality" />
                                                </Button.Content>
                                            </Button>
                                            <Button Grid.Column="1" Margin="4,0,0,0" Style="{StaticResource priorityButton}" vi:ViewModel.Scope="MoveDownInQueue">
                                                <Button.Content>
                                                    <Image Source="Resources\Down.ico" Width="18" RenderOptions.BitmapScalingMode="HighQuality" />
                                                </Button.Content>
                                            </Button>
                                        </Grid>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="Download" DisplayMemberBinding="{Binding Title}" Width="125" />
                            <GridViewColumn Header="Progress" DisplayMemberBinding="{Binding DownloadProgress, StringFormat='{}{0:0.00}%'}" Width="100" />
                        </GridView.Columns>
                    </GridView>
                </ListView.View>
            </ListView>
        </Grid>
    </DockPanel>
</vi:ModuleViewBase>